package com.xjh.serverinspect.security.service;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户详情服务
 * </p>
 *
 * @author xujinghui
 * @since 2024-12-12
 */
@Service
public class UserDetailServiceImpl implements UserDetailsService {

    /**
     * 用户名
     */
    @Value("${inspect.username:admin}")
    private String username;

    /**
     * 密码
     */
    @Value("${inspect.password:$2a$10$aFmkXlSt1QyiPxeYok7/t.OCG2Yx1gCkrYeosXvUpwsO8Ph3XW1QO}")
    private String password;

    /**
     * 加载用户信息
     *
     * @param username 用户名
     * @return UserDetails
     */
    @Override
    public UserDetails loadUserByUsername(String username) {
        if (!username.equals(this.username))
            throw new IllegalArgumentException("用户名错误");
        return new User(username, password, AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"));
    }

}